import { Event } from "vscode";
import { Disposables, IDisposable } from "../../common/utils/resourceLifecycle";
import { EQEnvsChangedEvent, EQEnvsWatcher, IEQEnvsWatcher } from "./watcher";

export class EQEnvsWatchers implements IEQEnvsWatcher, IDisposable {
    public readonly onChanged: Event<EQEnvsChangedEvent>;

    private readonly watcher = new EQEnvsWatcher();

    private readonly disposables = new Disposables();

    constructor(watchers: ReadonlyArray<IEQEnvsWatcher>) {
        this.onChanged = this.watcher.onChanged;
        watchers.forEach((w) => {
            const disposable = w.onChanged((e) => this.watcher.fire(e));
            this.disposables.push(disposable);
        });
    }

    public dispose(): void {
        this.disposables.dispose().ignoreErrors();
    }
}